/* to be used in conjunction with Program 3-4 */

void keypad_init(void);	
unsigned char keypad_getchar(void);

int main(void)
{
    unsigned char key;
    
    keypad_init();
    LCD_init();
    LCD_data('>');

    while(1)
    {
        key = keypad_getchar();
        LCD_data(key);      /* display the key label */
    }
}

/*--------------------------------------------------*/
/* This is a blocking function to read the keypad. */
/* When a key is pressed, it returns the key label.*/
/*--------------------------------------------------*/
unsigned char keypad_getchar(void)
{
    unsigned char key;
    /* wait until the previous key is released */
    do{
        while(keypad_getkey() != 0);
        delayMs(20);        /* wait to debounce */
    }while(keypad_getkey() != 0);

    do{
    key = keypad_getkey();
    delayMs(20);        /* wait to debounce */
    while(keypad_getkey() != key);

    return key;
}